<template>
  <el-row class="home">
    <el-col :span="8" style="padding-right: 20px">
      <el-card shadow="hover">
        <div class="user">
          <img
            src="http://lc-hyBuikQD.cn-n1.lcfile.com/iWkLoK9PjqkzMLwwYagKFf3UydrYuHCm/5f6d6a0f324cb4f51e57929069b00a81.png"
          />
          <div class="userinfo">
            <p class="name">admin</p>
            <p class="access">超级管理员</p>
          </div>
        </div>
        <div class="login-info">
          <p>上次登录时间：<span>2023.3.8</span></p>
          <p>上次登录地点：<span>南昌</span></p>
        </div>
      </el-card>
      <el-card style="margin-top: 20px">
        <el-table :data="tableData">
          <!-- 遍历对象 -->
          <el-table-column
            v-for="(value, key, i) in tableLabel"
            :key="i"
            :prop="key"
            :label="value"
          >
          </el-table-column>
        </el-table>
      </el-card>
    </el-col>
    <el-col :span="16">
      <div class="num">
        <el-card
          v-for="item in countData"
          :key="item.name"
          :body-style="{ display: 'flex', padding: 0 }"
        >
          <i
            class="icon"
            :class="`el-icon-${item.icon}`"
            :style="{ background: item.color }"
          ></i>
          <div class="detail">
            <p class="num">￥{{ item.value }}</p>
            <p class="txt">{{ item.name }}</p>
          </div>
        </el-card>
      </div>
      <el-card
        shadow="always"
        style="margin-bottom: 20px; height: 240px; overflow: visible"
      >
        <div class="lineEcharts" ref="lineEcharts" style="height: 240px"></div>
      </el-card>
      <div
        class="echarts"
        style="display: flex; justify-content: space-between"
      >
        <el-card shadow="always" style="height: 240px; width: 49%">
          <div class="barEcharts" ref="barEcharts" style="height: 240px"></div>
        </el-card>
        <el-card shadow="always" style="height: 240px; width: 49%">
          <div
            class="circleEcharts"
            ref="circleEcharts"
            style="height: 240px"
          ></div>
        </el-card>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import axios from "axios";
import * as echarts from "echarts";

export default {
  name: "User",
  data() {
    return {
      tableData: [],
      tableLabel: {
        name: "商品",
        todayBuy: "今日售出",
        monthBuy: "本月售出",
        totalBuy: "总共售出",
      },
      countData: [
        {
          name: "今日支付订单",
          value: 1234,
          icon: "success",
          color: "#2ec7c9",
        },
        {
          name: "今日收藏订单",
          value: 210,
          icon: "star-on",
          color: "#ffb980",
        },
        {
          name: "今日未支付订单",
          value: 1234,
          icon: "s-goods",
          color: "#5ab1ef",
        },
        {
          name: "本月支付订单",
          value: 1234,
          icon: "success",
          color: "#2ec7c9",
        },
        {
          name: "本月收藏订单",
          value: 210,
          icon: "star-on",
          color: "#ffb980",
        },
        {
          name: "本月未支付订单",
          value: 1234,
          icon: "s-goods",
          color: "#5ab1ef",
        },
      ],
      lineOption: {
        title: {
          text: "订单数量",
        },
        legend: {
          data: ["蛋糕", "面包", "小食", "配件"],
        },
        tooltip: {
          trigger: "axis",
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: [],
        },
        yAxis: {
          type: "value",
        },
        series: [],
      },
      barOption: {
        title: { text: "每日销量" },
        tooltip: {
          trigger: "item",
        },
        xAxis: {
          type: "category",
          data: ["蛋糕", "面包", "小食", "配件"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: [190, 100, 130, 80],
            type: "bar",
          },
        ],
      },
      circleOption: {
        title: {
          text: "用户分布",
        },
        tooltip: {
          trigger: "item",
        },
        series: [
          {
            name: "User From",
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            labelLine: {
              show: false,
            },
            data: [
              { value: 1048, name: "上海" },
              { value: 735, name: "北京" },
              { value: 580, name: "广州" },
              { value: 484, name: "南昌" },
              { value: 300, name: "深圳" },
            ],
          },
        ],
      },
    };
  },
  mounted() {
    this.getDashboardInfo();
  },
  methods: {
    getDashboardInfo() {
      axios.get("/api/home/getData").then((res) => {
        console.log("res======", res);
        const lineEcharts = echarts.init(this.$refs.lineEcharts);
        const barEcharts = echarts.init(this.$refs.barEcharts);
        const circleEcharts = echarts.init(this.$refs.circleEcharts);
        const { tableData, orderData, videoData, userData } = res.data.data;
        this.tableData = tableData;
        //折线图
        this.lineOption.xAxis.data = orderData.date;
        this.lineOption.series = orderData.series;
        //初始化
        lineEcharts.setOption(this.lineOption);
        barEcharts.setOption(this.barOption);
        circleEcharts.setOption(this.circleOption);
        // this.$set()
      });
    },
  },
};
</script>

 <style lang="less" scoped>
.home {
  margin: 10px;
  .user {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid #ccc;
    img {
      width: 150px;
      height: 150px;
      border-radius: 50%;
      margin-right: 40px;
    }
    &info {
      .name {
        font-size: 28px;
        margin-bottom: 10px;
      }
      .access {
        color: #999999;
      }
    }
  }
  .login-info {
    p {
      line-height: 28px;
      font-size: 14px;
      color: #999999;
      span {
        color: #666666;
        margin-left: 60px;
      }
    }
  }
  .num {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .el-card {
      width: 32%;
      margin-bottom: 20px;
    }
    .icon {
      font-size: 28px;
      width: 80px;
      height: 80px;
      text-align: center;
      line-height: 80px;
      color: #fff;
    }
    .detail {
      margin-left: 15px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .num {
        font-size: 28px;
        margin-bottom: 10px;
      }
      .txt {
        font-size: 14px;
        text-align: center;
        color: #999999;
      }
    }
  }
}
</style>